package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.BuildingMapper;
import com.ruoyi.system.domain.Building;
import com.ruoyi.system.service.IBuildingService;
import com.ruoyi.common.core.text.Convert;

/**
 * 小区楼栋信息Service业务层处理
 * 
 * @author 祖新宇
 * @date 2024-12-13
 */
@Service
public class BuildingServiceImpl extends ServiceImpl<BuildingMapper,Building> implements IBuildingService

{
    @Autowired
    private BuildingMapper buildingMapper;

    /**
     * 查询小区楼栋信息
     * 
     * @param id 小区楼栋信息主键
     * @return 小区楼栋信息
     */
    @Override
    public Building selectBuildingById(Long id)
    {
        return buildingMapper.selectBuildingById(id);
    }

    /**
     * 查询小区楼栋信息列表
     * 
     * @param building 小区楼栋信息
     * @return 小区楼栋信息
     */
    @Override
    public List<Building> selectBuildingList(Building building)
    {
        return buildingMapper.selectBuildingList(building);
    }

    /**
     * 新增小区楼栋信息
     * 
     * @param building 小区楼栋信息
     * @return 结果
     */
    @Override
    public int insertBuilding(Building building)
    {
        building.setCreateTime(DateUtils.getNowDate());
        return buildingMapper.insertBuilding(building);
    }

    /**
     * 修改小区楼栋信息
     * 
     * @param building 小区楼栋信息
     * @return 结果
     */
    @Override
    public int updateBuilding(Building building)
    {
        building.setUpdateTime(DateUtils.getNowDate());
        return buildingMapper.updateBuilding(building);
    }

    /**
     * 批量删除小区楼栋信息
     * 
     * @param ids 需要删除的小区楼栋信息主键
     * @return 结果
     */
    @Override
    public int deleteBuildingByIds(String ids)
    {
        return buildingMapper.deleteBuildingByIds(Convert.toStrArray(ids));
    }

    /**
     * 批量软删除小区楼栋信息
     *
     * @param ids 需要软删除的小区楼栋信息主键
     * @return 结果
     */
    @Override
    public int softDeleteBuildingByIds(String ids)
    {
        String[] strArray = Convert.toStrArray(ids);
        int count = 0;
        for (String s : strArray) {
            Building building = buildingMapper.selectBuildingById(Long.valueOf(s));
            building.setIsDelete(1);
            int i = buildingMapper.updateBuilding(building);
            count = count + i;
        }
        return count;
    }

    /**
     * 删除小区楼栋信息信息
     * 
     * @param id 小区楼栋信息主键
     * @return 结果
     */
    @Override
    public int deleteBuildingById(Long id)
    {
        return buildingMapper.deleteBuildingById(id);
    }
}
